package com.functest.jpwise

import com.functest.jpwise.algo.CombinatorialAlgorithm
import com.functest.jpwise.core.CombinationTable
import com.functest.jpwise.core.ParameterValue
import com.functest.jpwise.core.SimpleValue
import com.functest.jpwise.core.TestGenerator
import com.functest.jpwise.core.TestInput
import com.functest.jpwise.core.TestParameter
import com.functest.framework.BaseFunctionalTest
import org.testng.annotations.Test

import static com.functest.jpwise.ClosureBasedMatcher.valueWith

/**
 * @author: DavydovMD
 * Date: 25.09.13
 * Time: 13:22
 */
class RestrictionBuilderTest extends BaseFunctionalTest {
    //final private static Logger logger = LoggerFactory.getLogger(RestrictionsBuilder)

    @Test
    void testParams() {
        TestInput input = new TestInput()
        input.add(new TestParameter("A", [SimpleValue.of("a1", 1), SimpleValue.of("a2", 2), SimpleValue.of("a3", 3)]))
        input.add(new SmartParameter("B", [SimpleValue.of('b1'), SimpleValue.of('b2')], new RestrictionsBuilder("B")
                .restrict(valueWith { it.name == 'b2' }, valueWith { it.name == 'a3' }.and { ParameterValue v -> v.get() == 3 })
                .build())
        )
        input.add(new TestParameter("C", [SimpleValue.of("c1", 1), SimpleValue.of("c2", 2)]))
        TestGenerator generator = new TestGenerator(input)
        generator.generate(new CombinatorialAlgorithm(), 0)
        CombinationTable table = generator.result()
        table.combinations()
        table.combinations().each {
            logger.info "$it"
        }
        assert table.combinations().size() == 10
        assert table.combinations().findAll { it.getValue(0).name == 'a3' && it.getValue(1).get() == 'b2' }.size() == 0

    }

}
